/*
 * Lec20e.cpp
 *   Program to demonstrate class templates.
 *  Created on: Mar 1, 2014
 *      Author: Anthony Varghese - This is from the Savitch book
 */

#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

#include "PFArrayBak.cpp"
using PFArraySavitch::PFArray;
using PFArraySavitch::PFArrayBak;

int main( )
{
    int cap;
    cout << "Enter capacity of this super array: ";
    cin >> cap;
    PFArrayBak<string> a(cap);

    cout << "Enter " << cap << " strings.\n";
    cout << "Separated by blanks.\n";

    string next;
    for (int i = 0; i < cap; i++)
    {
        cin >> next;
        a.addElement(next);
    }

    int count = a.getNumberUsed( );
    cout << "The following " << count
         << " strings read and stored:\n";
    int index;
    for (index = 0; index < count; index++)
        cout << a[index] << " ";
    cout << endl;

    cout << "Backing up array.\n";
    a.backup( );

    cout << "emptying array.\n";
    a.emptyArray( );
    cout << a.getNumberUsed( )
         << " strings are now stored in the array.\n";

    cout << "Restoring array.\n";
    a.restore( );
    count = a.getNumberUsed( );
    cout << "The following " << count
         << " strings are now stored:\n";
    for (index = 0; index < count; index++)
        cout << a[index] << " ";
    cout << endl;

    cout << "End of demonstration.\n";
    return 0;
}
